package com.dms.wuziqi.mapper;


import com.dms.wuziqi.pojo.Loan;
import org.apache.ibatis.annotations.*;

import java.util.Date;
import java.util.List;

@Mapper
public interface LoanMapper {
    @Insert("insert into  loaninfo(loan_use,loan_account,loan_date,loan_day,loan_userId) values (#{loanUse},#{loan_account},#{loanDate},#{loanDay},#{loanUserId})")
    void insertLoan(String loanUse, long loan_account, Date loanDate,int loanDay, int loanUserId);
    @Select("select * from loaninfo where loan_userId=#{userId}")
    @Results({
            @Result(column = "loan_id",property = "LoanId"),
            @Result(column = "loan_userId",property = "LoanUserId"),
            @Result(column = "loan_use",property = "LoanUse"),
            @Result(column = "loan_date",property = "LoanDate"),
            @Result(column = "loan_day",property = "LoanDay"),
            @Result(column = "loan_account",property = "LoanAccount"),
            @Result(column = "loan_auit",property = "auit")
    })
    List<Loan> getAllLoanByUserId(int userId);
    @Select("select * from loaninfo where loan_id=#{loanId}")
    @Results({
            @Result(column = "loan_id",property = "LoanId"),
            @Result(column = "loan_userId",property = "LoanUserId"),
            @Result(column = "loan_use",property = "LoanUse"),
            @Result(column = "loan_date",property = "LoanDate"),
            @Result(column = "loan_day",property = "LoanDay"),
            @Result(column = "loan_account",property = "LoanAccount"),
            @Result(column = "loan_auit",property = "auit"),
            @Result(column = "loan_userId",property ="user",one=@One(select = "com.dms.wuziqi.mapper.UserMapper.findUserById") )
    })
    Loan getLoanById(int loanId);
    @Select("select * from loaninfo")
    @Results({
            @Result(column = "loan_id",property = "LoanId"),
            @Result(column = "loan_userId",property = "LoanUserId"),
            @Result(column = "loan_use",property = "LoanUse"),
            @Result(column = "loan_date",property = "LoanDate"),
            @Result(column = "loan_day",property = "LoanDay"),
            @Result(column = "loan_account",property = "LoanAccount"),
            @Result(column = "loan_auit",property = "auit"),
            @Result(column = "loan_userId",property ="user",one=@One(select = "com.dms.wuziqi.mapper.UserMapper.findUserById") )
    })
    List<Loan> getAllLoan();
    @Update("update loaninfo set loan_auit='已审核' where loan_id=#{LoanId}")
    @Result(column = "loan_id",property = "LoanId")
    void updateAuit(int LoanId);
}
